package lambda_expression;

import lambda_expression.model.Person;

import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App {

    //        FileFilter
    //        Comparable
    //        Comparator
    //        Runnable

    public static void main( String[] args ){

        Person[] persons = {
                new Person("张三", 12),
                new Person("里斯", 23),
                new Person("王五", 8)
        };

//        Arrays.sort(persons, new Comparator<Person>() {
//            @Override
//            public int compare(Person o1, Person o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        });

        // lambda
        Arrays.sort(persons, (Person p1, Person p2) -> {
            return p2.getAge() - p1.getAge() ;
        });


        for (Person person : persons) {
            System.out.println(person);
        }





        IUserCredential ic = new IUserCredential() {
            @Override
            public String verifyUser(String username) {
                return username.equals("admin") ? "管理员" : "会员";
            }
        };
        System.out.println(ic.verifyUser("admin"));

        // lambda表达式
        IUserCredential ic2 = (String username) -> {
            return username.equals("admin") ? "管理员2" : "会员2";
        };
        System.out.println(ic2.verifyUser("user"));
    }
}
